#ifndef TITLECOMPOSITE_H_
#define TITLECOMPOSITE_H_

#include <irrlicht.h>

#include "StatusBar.h"
#include "LabelNode.h"

#include <map>

using std::map;

using namespace irr;


//
//class ColorCombo {
//	irr::video::SColor color;
//	float highBound;
//	int IDVal;
//	ColorCombo(irr::video::SColor col, float hb, int id) {
//		color = col;
//		highBound = hb;
//		IDVal = id;
//	}
//};

enum e_barType { TCN_NORMAL_BAR };	

class TitleCompositeNode : public irr::scene::ISceneNode {
	map<irr::core::stringw, ContainedNode*> m_containedNodes;
	irr::core::aabbox3d<f32> m_box;

	irr::video::SMaterial m_material;
	irr::scene::ISceneCollisionManager* m_collisionManager;
	
	public:
		TitleCompositeNode(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::scene::ISceneCollisionManager* col, s32 id)
		 : ISceneNode(parent, mgr, id), m_collisionManager(col) {
			m_box = irr::core::aabbox3d<f32>(-7,-3,-1,7,3,1);
			m_material.Lighting = false;
			m_material.Wireframe = false;
			AutomaticCullingState = scene::EAC_OFF;
			irr::core::vector3df edges[12];
			Parent->getBoundingBox().getEdges(edges);
			float h = getPosition().Y;
			for(int i = 0; i < 12; i++)
				if(edges[i].Y > h)
					h=edges[i].Y;
			
			irr::core::vector3df temp = getPosition();
			temp.Y = h;
			setPosition(temp);
		}
		
		virtual ~TitleCompositeNode() {
		    std::map<irr::core::stringw, ContainedNode*>::const_iterator iter;
		    for (iter = m_containedNodes.begin(); iter != m_containedNodes.end(); ++iter) {
		    	delete iter->second;
		    }
		    
		    this->drop();
		}
		
		StatusBar* addBar(irr::core::stringw name, e_barType type);
		LabelNode* addLabel(irr::core::stringw stringRef, irr::core::stringw stringName);
		
		LabelNode* getLabelNode(irr::core::stringw ref) { return static_cast<LabelNode*>(m_containedNodes[ref]); }
		StatusBar* getBarNode(irr::core::stringw ref) { return static_cast<StatusBar*>(m_containedNodes[ref]); }
		
		virtual void OnRegisterSceneNode() {
			if (IsVisible) {
                SceneManager->registerNodeForRendering(this);
                ISceneNode::OnRegisterSceneNode();
			}
		}
		
		virtual void render();

		virtual const irr::core::aabbox3d<f32>& getBoundingBox() const {
			return m_box;
		}
		
		virtual u32 getMaterialCount() {
			return 1;
		}
		
		virtual video::SMaterial& getMaterial(u32 i) {
			return m_material;
		} 
};

#endif /*TITLECOMPOSITE_H_*/
